<?php
namespace App\listeners ;
use Illuminate\Log\Writer;
use Monolog\Logger;

class QueryListener
{
    public $log ;
    public function __construct()
    {
        $this->log = new Writer(new Logger('QUERY')) ;
        $this->log->useDailyFiles(storage_path().'/logs/sql.log');
    }

    public function handle(\Illuminate\Database\Events\QueryExecuted $query){
        $this->log->info("SQL:",['sql' => $query->sql , 'bindings' => $query->bindings , 'time' => $query->time.'ms']);
    }
}